package com.xuzimian.globaldemo.mq.rabbitmq.util;

import com.rabbitmq.jms.admin.RMQConnectionFactory;
import com.xuzimian.globaldemo.mq.rabbitmq.constants.Config;

import javax.jms.Connection;
import javax.jms.JMSException;
import java.io.IOException;
import java.util.concurrent.TimeoutException;

/***
 * @Description rabbitmq jms客户端帮助类
 * @author xzm
 */
public class JmsMqUtil {

    /**
     * 创建一个JMS的RabbitMq 连接对象
     *
     * @return
     * @throws TimeoutException
     * @throws IOException
     */
    public static Connection createQueueConnection() throws JMSException {
        RMQConnectionFactory connectionFactory = new RMQConnectionFactory();
        connectionFactory.setUsername(Config.MQServerConect.USERNAME);
        connectionFactory.setPassword(Config.MQServerConect.PASSWORD);
        connectionFactory.setVirtualHost(Config.MQServerConect.VIRTUALHOST_DEFAULT);
        connectionFactory.setHost(Config.MQServerConect.HOST);
        connectionFactory.setPort(Config.MQServerConect.PORT_AMQP);
        return connectionFactory.createConnection();
    }


}
